Add missing C# bindings to match MaaFramework C API#27
Conversation
- Add MaaMacOSControllerCreate, MaaAndroidNativeControllerCreate, MaaReplayControllerCreate, MaaRecordControllerCreate P/Invoke - Add MaaControllerPostRelativeMove P/Invoke - Add MaaTaskerGetWaitFreezesDetail P/Invoke - Add MaaToolkitMacOS P/Invoke (CheckPermission, RequestPermission, RevealPermissionSettings) - Update MaaDbgControllerCreate to new 1-param signature - Add MaaMacOSController, MaaAndroidNativeController, MaaReplayController, MaaRecordController wrapper classes - Update MaaDbgController wrapper for new API - Add RelativeMove to IMaaController/MaaController - Add GetWaitFreezesDetail to IMaaTasker/MaaTasker - Add MacOSScreencapMethod, MacOSInputMethod, MacOSPermission enums - Add MaaWfId type alias - Add IMaaToolkitMacOS interface and implementation - Add Node.WaitFreezes messages to MaaMsg Agent-Logs-Url: https://github.com/MaaXYZ/MaaFramework.Binding.CSharp/sessions/201d767e-cec0-4888-b09f-8b7a74837c9a Co-authored-by: MistEO <18511905+MistEO@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR updates the C# binding layer to close gaps with the upstream MaaFramework C API, adding new controller/toolkit bindings and extending the controller/tasker interfaces accordingly.
Changes:
- Added new controller wrappers (macOS, Android native, record/replay) and updated
MaaDbgControllerCreateto the new 1-parameter signature. - Exposed new controller action
RelativeMove(dx, dy)and added tasker queryGetWaitFreezesDetail(...)using the existing two-pass size query pattern. - Added macOS toolkit permission APIs (
CheckPermission,RequestPermission,RevealPermissionSettings), enums/type aliases, and new MaaMsg entries for WaitFreezes notifications.
Reviewed changes
Copilot reviewed 21 out of 21 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/MaaFramework.Binding/MaaMsg.cs | Adds MaaMsg.Node.WaitFreezes.* message constants. |
| src/MaaFramework.Binding/MaaDef.cs | Introduces MaaWfId type alias for wait-freezes IDs. |
| src/MaaFramework.Binding/IMaaToolkit.cs | Extends toolkit API with MacOS property and new IMaaToolkitMacOS interface. |
| src/MaaFramework.Binding/IMaaTasker.cs | Adds GetWaitFreezesDetail to the tasker interface. |
| src/MaaFramework.Binding/IMaaController.cs | Adds RelativeMove(dx, dy) to the controller interface. |
| src/MaaFramework.Binding/Enums/Controllers/MacOSScreencapMethod.cs | Adds macOS screencap method enum for the new controller. |
| src/MaaFramework.Binding/Enums/Controllers/MacOSPermission.cs | Adds macOS permission enum for toolkit permission APIs. |
| src/MaaFramework.Binding/Enums/Controllers/MacOSInputMethod.cs | Adds macOS input method flags enum for the new controller. |
| src/MaaFramework.Binding.Native/MaaToolkit.cs | Implements IMaaToolkit.MacOS via MacOSClass calling new toolkit P/Invokes. |
| src/MaaFramework.Binding.Native/MaaTasker.cs | Implements GetWaitFreezesDetail wrapper over the new P/Invoke. |
| src/MaaFramework.Binding.Native/MaaController/MaaReplayController.cs | New replay controller wrapper over MaaReplayControllerCreate. |
| src/MaaFramework.Binding.Native/MaaController/MaaRecordController.cs | New record controller wrapper over MaaRecordControllerCreate. |
| src/MaaFramework.Binding.Native/MaaController/MaaMacOSController.cs | New macOS controller wrapper over MaaMacOSControllerCreate. |
| src/MaaFramework.Binding.Native/MaaController/MaaDbgController.cs | Updates managed wrapper to match new MaaDbgControllerCreate(readPath) signature. |
| src/MaaFramework.Binding.Native/MaaController/MaaAndroidNativeController.cs | New Android native controller wrapper over MaaAndroidNativeControllerCreate. |
| src/MaaFramework.Binding.Native/MaaController.cs | Implements IMaaController.RelativeMove via MaaControllerPostRelativeMove. |
| src/MaaFramework.Binding.Native/Interop/Toolkit/MacOS/MaaToolkitMacOS.cs | Adds MaaToolkit macOS permission P/Invokes. |
| src/MaaFramework.Binding.Native/Interop/Toolkit/MaaToolkitDef.cs | Adds MaaMacOSPermission interop alias. |
| src/MaaFramework.Binding.Native/Interop/Framework/MaaDef.cs | Adds macOS controller interop aliases and MaaWfId. |
| src/MaaFramework.Binding.Native/Interop/Framework/Instance/MaaTasker.cs | Adds MaaTaskerGetWaitFreezesDetail P/Invoke signature. |
| src/MaaFramework.Binding.Native/Interop/Framework/Instance/MaaController.cs | Adds new controller factory P/Invokes and MaaControllerPostRelativeMove; updates dbg factory signature. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| /// Gets the MaaToolkit Desktop. | ||
| /// </summary> | ||
| IMaaToolkitDesktop Desktop { get; } | ||
|
|
||
| /// <summary> | ||
| /// Gets the MaaToolkit macOS helper. | ||
| /// </summary> | ||
| IMaaToolkitMacOS MacOS { get; } |
There was a problem hiding this comment.
Adding a new member to the public IMaaToolkit interface is a source/binary breaking change for any downstream implementations. If maintaining compatibility is a goal, consider introducing a new derived interface (e.g., IMaaToolkitV2) or using a default interface implementation for MacOS (e.g., throwing PlatformNotSupportedException) so existing implementers don’t break.
| /// <param name="dx">The relative horizontal offset.</param> | ||
| /// <param name="dy">The relative vertical offset.</param> | ||
| /// <returns>A relative move <see cref="MaaJob"/>.</returns> | ||
| MaaJob RelativeMove(int dx, int dy); |
There was a problem hiding this comment.
Adding RelativeMove to the public IMaaController interface is a breaking change for any external IMaaController implementations. If compatibility matters, consider a default interface implementation (e.g., throw NotSupportedException) or introducing a new derived interface so existing implementers continue to compile/run.
| MaaJob RelativeMove(int dx, int dy); | |
| MaaJob RelativeMove(int dx, int dy) | |
| { | |
| throw new global::System.NotSupportedException("RelativeMove is not supported by this controller implementation."); | |
| } |
| /// <param name="recoIdList">The recognition id list.</param> | ||
| /// <param name="roi">The region of interest.</param> | ||
| /// <returns><see langword="true"/> if query was successful; otherwise, <see langword="false"/>.</returns> | ||
| bool GetWaitFreezesDetail(MaaWfId wfId, out string nodeName, out string phase, out bool isSucceeded, out ulong elapsedMs, out MaaRecoId[] recoIdList, IMaaRectBuffer? roi); |
There was a problem hiding this comment.
Adding GetWaitFreezesDetail to the public IMaaTasker interface is a breaking change for any external IMaaTasker implementations. If compatibility is important, consider a default interface implementation or introducing a new derived interface (and having MaaTasker implement it) to avoid forcing downstream recompilation.
| bool GetWaitFreezesDetail(MaaWfId wfId, out string nodeName, out string phase, out bool isSucceeded, out ulong elapsedMs, out MaaRecoId[] recoIdList, IMaaRectBuffer? roi); | |
| bool GetWaitFreezesDetail(MaaWfId wfId, out string nodeName, out string phase, out bool isSucceeded, out ulong elapsedMs, out MaaRecoId[] recoIdList, IMaaRectBuffer? roi) | |
| { | |
| nodeName = string.Empty; | |
| phase = string.Empty; | |
| isSucceeded = false; | |
| elapsedMs = 0; | |
| recoIdList = System.Array.Empty<MaaRecoId>(); | |
| return false; | |
| } |
Audit of
MaaFramework/includeheaders against the C# binding, filling all gaps.New controller types
MaaMacOSController— wrapsMaaMacOSControllerCreate(window_id, screencap_method, input_method)MaaAndroidNativeController— wrapsMaaAndroidNativeControllerCreate(config_json)MaaReplayController— wrapsMaaReplayControllerCreate(recording_path)MaaRecordController— wrapsMaaRecordControllerCreate(inner, recording_path)Updated
MaaDbgControllerMaaDbgControllerCreatesignature changed upstream from 4 params(readPath, writePath, type, config)to 1 param(readPath). Updated P/Invoke and wrapper accordingly.New controller action
MaaControllerPostRelativeMove(ctrl, dx, dy)exposed asIMaaController.RelativeMove(int dx, int dy)New tasker query
MaaTaskerGetWaitFreezesDetailexposed asIMaaTasker.GetWaitFreezesDetail(...)with the same two-pass size-query pattern used byGetTaskDetailmacOS toolkit
MaaToolkitMacOSCheckPermission,MaaToolkitMacOSRequestPermission,MaaToolkitMacOSRevealPermissionSettingsIMaaToolkitMacOSinterface + implementation onMaaToolkit.MacOSNew enums & type aliases
MacOSScreencapMethod,MacOSInputMethod,MacOSPermissionenumsMaaWfId,MaaMacOSScreencapMethod,MaaMacOSInputMethod,MaaMacOSPermissionglobal using aliasesNew MaaMsg entries
MaaMsg.Node.WaitFreezes.{Starting,Prefix,Succeeded,Failed}Usage example
Summary by Sourcery
通过添加缺失的控制器类型、任务器查询、macOS 工具包绑定以及相关枚举/消息,使 C# 绑定与最新的 MaaFramework C API 保持一致。
新功能:
IMaaController中添加RelativeMove控制器动作,以相对偏移量移动指针。IMaaTasker中引入GetWaitFreezesDetail,通过原生MaaTaskerGetWaitFreezesDetailAPI 获取等待冻结(wait-freeze)诊断信息。IMaaToolkit.MacOS和原生MaaToolkitMacOSP/Invoke 绑定,暴露 macOS 工具包权限辅助方法。MaaWfId的支持。MaaMsg,增加Node.WaitFreezes消息常量,用于等待冻结生命周期事件。增强:
MaaDbgController以匹配简化后的原生MaaDbgControllerCreate函数签名,并精简其托管包装实现。Original summary in English
Summary by Sourcery
Align C# bindings with the latest MaaFramework C API by adding missing controller types, tasker queries, macOS toolkit bindings, and associated enums/messages.
New Features:
Enhancements: